import Farm2Request from "@/service/remoteRequests/Farm2Request";

/**获得知识标签的展示风格
 * import farmKnowViewUtils from '@/hook/farmKnowViewUtils'
 * @param type
 * @returns
 */
const getTagType = (type: string): string => {
  if (type == "0") {
    return "danger";
  }
  if (type == "3") {
    return "success";
  }
  return "primary";
};

const splitTags = (tags?: string): string[] => {

  const tagTitles = tags || "";

  const tagsArray = tagTitles.split(",").map((item) => item.trim());

  return tagsArray.filter((item) => item !== "");
};

/**将附件id字符串，多个用逗号分隔
 * import farmKnowViewUtils from '@/hook/farmKnowViewUtils'
 * @param imgids  用逗号分隔的多个id
 * @returns
 */
const getImgFileUrls = (imgids: string): string[] => {
  if (!imgids || imgids.trim() === "") {

    return [];
  }


  return imgids
    .split(",")
    .map((id) => id.trim())
    .filter((id) => id !== "")
    .map((id) => Farm2Request.getFullPath("api/files/download/" + id));
};

export default { getTagType, splitTags, getImgFileUrls };
